package com.kk.demo.java8.stream.base01;

import java.util.Arrays;
import java.util.List;

/**
 * 使用并行集合
 * @author liujun
 * @date 2016年8月28日
 * @verion 0.0.1
 */
public class StreamCollectorStr {

    public StreamCollectorStr() {
    }

    public static void main(String[] args) {
        StreamCollectorStr stream = new StreamCollectorStr();
        stream.list();

    }

    public void list() {
        List<String> list2 = Arrays.asList("abc,", "def,", "gbi,", "hij,");

        String rsp = list2.stream().parallel().collect(StringBuilder::new, (str, item) -> {
            str.append(item);
        }, (res1, res2) -> {
            System.out.println("当前线程:" + Thread.currentThread().getId() + ",res1:" + res1 + ",res2:" + res2);
            res1.append(res2);
        }).toString();

        System.out.println("并行结果:" + rsp);
        String rsp2 = list2.stream().collect(StringBuilder::new, (str, item) -> {
            str.append(item);
        }, (res1, res2) -> {
            System.out.println("当前线程:" + Thread.currentThread().getId() + ",res1:" + res1 + ",res2:" + res2);
            res1.append(res2);
        }).toString();

        System.out.println("结果:" + rsp2);
    }

}